<template>
    <el-row :gutter="20">
        <el-col :span="11">
            <div class="block mt mb">
                <el-tag class="block">退款客户：{{oinfo.clientname}} </el-tag>
                <el-tag class="block mt mb">退款金额：{{oinfo.money}} 元</el-tag>
                <el-tag class="block mt mb">退款类型：{{oinfo.isstore?'退卡转余额':'仅退款'}}</el-tag>
                <el-tag class="block">退款描述：{{oinfo.remarks}}</el-tag>
                <div class="block mt" v-for="(a, k) in alogs" v-if="alogs.length" :key="k">
                    <el-tag type="info">退款账户：{{a.name}}</el-tag>
                    <el-tag type="info" class="ml">退款金额：{{a.money}} 元</el-tag>
                </div>
            </div>
            <el-table :data="slogs" :stripe="true" v-if="oinfo.ordertype==10 && !oinfo.isstore" height="200">
                <el-table-column type="index" label="#"></el-table-column>
                <el-table-column prop="name" label="项目"></el-table-column>
                <el-table-column prop="cardtype" label="所属">
                    <template slot-scope="scope">
                        <el-tag size="mini" type="info" v-if="scope.row.cardtype==1">期卡</el-tag>
                        <el-tag size="mini" type="success" v-else>疗程</el-tag>
                    </template>
                </el-table-column>
            </el-table>
        </el-col>
        <el-col :span="13">
            <div class="block" v-if="!oinfo.isstore">
                <div class="block ov mt mb" v-show="oinfo.status==1">
                    <el-alert type="info" class="w300 fl" title="若员工离职等，可添加店长。"></el-alert>
                    <el-button size="mini" icon="el-icon-plus" type="primary" class="fr" @click="addUsers">业绩人员</el-button>
                </div>
                <el-table :data="ulist" height="300">
                    <el-table-column type="index" label="#"></el-table-column>
                    <el-table-column prop="name" label="姓名"></el-table-column>
                    <el-table-column prop="worknum" label="工号"></el-table-column>
                    <el-table-column prop="feat" label="业绩">
                        <template slot-scope="scope">
                            <el-input v-model="scope.row.feat" size="mini" placeholder="扣除业绩" @change="chg"></el-input>
                        </template>
                    </el-table-column>
                    <el-table-column label="移除">
                        <template slot-scope="scope">
                            <el-button type="danger" icon="el-icon-close" size="mini" @click="rmRow(scope.$index)"></el-button>
                        </template>
                    </el-table-column>
                </el-table>
                <el-tag size="mini" type="danger" class="fr mb">未扣除业绩：{{fenpei}} 元</el-tag>
            </div>
            <div class="block mt right clear ov">
                <el-button icon="el-icon-close" class="fr ml" @click="close">取消关闭</el-button>
                <el-alert type="info" title="当前订单已分配" class="w200 fl" v-if="oinfo.status==2"></el-alert>
                <el-button type="warning" icon="el-icon-upload" class="fr" @click="againAllot" v-else>重新分配业绩</el-button>
            </div>
        </el-col>
    </el-row>
</template>
<script>
import C from '@/common/common.js'
import P from '@/service/shop/popup.js'

export default {
  name: 'backCardInfo',
  data () {
    return {
      oinfo: {},
      slogs: [],
      alogs: [],
      ulist: [],
      request: C.getDatas()
    }
  },
  methods: {
    againAllot: function () {
      if (this.fenpei != 0) {
        C.error('未扣除业绩不正确')
        return false
      }
      let users = []
      this.ulist.forEach((v) => {
        if (v.feat != 0) {
          users.push(v)
        }
      })

      let data = {
        oid: this.oinfo.id,
        user: users,
        type: this.oinfo.ordertype
      }

      C.confirm('确定重新分配当前扣除业绩？', async index => {
        let res = await C.ajax('/shop/backcard/againallot', { data: JSON.stringify(data) }, 'post')
        if (res) {
          C.success(res.data)
        }
      })
    },
    addUsers: async function () {
      let res = await P.userPopup({ gid: this.request.gid })
      if (res) {
        this.ulist.push({
          userid: res.id,
          name: res.name,
          worknum: res.worknum,
          feat: '',
          bumenid: res.bumenid,
          xiaozuid: res.xiaozuid
        })
      }
    },
    rmRow: function (i) {
      this.ulist.splice(i, 1)
    },
    chg: function () {
      this.ulist = JSON.parse(JSON.stringify(this.ulist))
    },
    time: function (unix) {
      return C.time(unix)
    },
    close: function () {
      C.closewin()
    }
  },
  computed: {
    fenpei: function () {
      let yj = 0
      this.ulist.forEach((v) => {
        yj += v.feat * 1
      })
      return Number(-this.oinfo.money - yj).toFixed(2)
    }
  },
  mounted: async function () {
    let data = await C.ajax('/shop/backcard/lookinfo', { id: this.request.id }, 'post')
    if (data) {
      this.oinfo = data.oinfo
      this.slogs = data.slogs
      this.alogs = data.alogs
      this.oinfo.clientname = data.oinfo.name
      data.ulist.forEach((v) => {
        this.ulist.push({
          id: v.id,
          userid: v.userid,
          name: v.name,
          worknum: v.worknum,
          bumenid: v.bumenid,
          xiaozuid: v.xiaozuid,
          feat: v.money
        })
      })
    }
  }
}
</script>
<style>
.ov {
    overflow: hidden;
}

.ov-x {
    overflow-x: hidden;
}

.fl {
    float: left;
}

.fr {
    float: right;
}

.clear {
    clear: both;
}

.none {
    display: none;
}

.block {
    display: block;
}

.handel {
    cursor: pointer;
}






/*背景颜色-前景颜色*/

.bg-dark {
    background: #F9FAFC;
}

.bg-extra {
    background: #EFF2F7;
}

.bg-light {
    background: #E5E9F2;
}

.bg-gray {
    background: #D3DCE6;
}

.bg-silver {
    background: #8492A6;
}

.bg-black {
    background: #324057;
}

.white {
    color: white;
}

.black {
    color: #324057;
}

.green {
    color: green;
}

.blue {
    color: blue;
}

.red {
    color: red;
}

.color-nan {
    color: #2a91f7;
}

.color-nv {
    color: #f7992a;
}






/*其他样式*/

html {
    font-family: Helvetica Neue, Helvetica, PingFang SC, Hiragino Sans GB, Microsoft YaHei, SimSun, sans-serif;
    font-weight: 400;
}

.title {
    font-size: 16px;
    font-family: "Helvetica Neue", "Helvetica", "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", "微软雅黑", Arial, sans-serif;
    line-height: 26px;
    margin: 10px 0;
}

.border {
    border: 1px solid #dfe6ec;
    border-radius: 4px;
    padding: 0 8px;
}

.bd {
    border: 1px solid #dfe6ec;
}

.border-b {
    border-bottom: 1px solid #dfe6ec;
}

.border-t {
    border-top: 1px solid #dfe6ec;
}

.bd-l {
    border-left: 1px dashed #dfe6ec;
}

.bd-t {
    border-top: 1px dashed #dfe6ec;
}

.bd-r {
    border-radius: 50%;
}

.underline {
    text-decoration: underline;
}






/*边距*/

.p0 {
    padding: 0 !important;
}

.m0 {
    margin: 0 !important;
}

.m10 {
    margin: 10px !important;
}

.m15 {
    margin: 15px !important;
}

.p10 {
    padding: 10px !important;
}

.p15 {
    padding: 15px !important;
}

.ml {
    margin-left: 15px !important;
}

.mr {
    margin-right: 15px !important;
}

.mb {
    margin-bottom: 15px !important;
}

.mt {
    margin-top: 15px !important;
}

.pl {
    padding-left: 15px !important;
}

.pl0 {
    padding-left: 0 !important;
}

.pr {
    padding-right: 15px !important;
}

.pr0 {
    padding-right: 0 !important;
}

.pb {
    padding-bottom: 15px !important;
}

.pt {
    padding-top: 15px !important;
}

.center {
    text-align: center !important;
}

.left {
    text-align: left !important;
}

.right {
    text-align: right !important;
}

.w100 {
    width: 100px !important;
}

.w150 {
    width: 150px !important;
}

.w200 {
    width: 200px !important;
}

.w300 {
    width: 300px !important;
}

.w400 {
    width: 400px !important;
}

.w500 {
    width: 500px !important;
}

.w30 {
    width: 30%;
}

.w50 {
    width: 50%;
}

.width95 {
    width: 95%;
}

.width {
    width: 100% !important;
}

.h200 {
    height: 200px;
}

.h300 {
    height: 300px;
}

.h500 {
    height: 500px;
}

.h600 {
    height: 600px;
}

.h700 {
    height: 700px;
}

.h800 {
    height: 800px;
}

.l28 {
    line-height: 28px;
}

.l30 {
    line-height: 30px;
}

.l50 {
    line-height: 50px;
}






/*附加订制样式*/

.el-row {
    margin: 0 !important;
}

.el-table .cell {
    padding: 0;
    text-align: center;
}

.el-textarea__inner {
    resize: none;
}

.el-input.is-disabled .el-input__inner {
    color: #20A0FF;
}

.el-textarea.is-disabled .el-textarea__inner {
    color: #444;
}

.el-switch {
    line-height: 0;
}

.el-checkbox+.el-checkbox {
    margin-left: 0;
}

.el-checkbox {
    margin-right: 20px;
}

.el-autocomplete-suggestion li {
    padding: 4px 20px;
    line-height: 20px;
}

.el-table th {
    padding: 10px 0;
}

.el-table td {
    padding: 4px 0;
}
</style>